def isPrime(x):
    if x == 1: return False
    y = True
    z = x - 1
    while z > 1:
        if not x % z:
            y = False
            break
        z -= 1
    return t

l = input ()
r =[]
for i in range(len(e)):
    for z in range(i + 1,len(l) +  1):
        x = int (l[i:z])
        if isPrime(x):
            r += [x]
print(max(r) if r else 0)
